package com.ruoyi.ycl.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ycl.domain.vo.BsJctzVo;
import com.ruoyi.ycl.domain.bo.BsJctzBo;
import com.ruoyi.ycl.service.IBsJctzService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 原材料进场台账
 *
 * @author zyb
 * @date 2024-06-05
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ycl/bsJctz")
public class BsJctzController extends BaseController {

    private final IBsJctzService iBsJctzService;

    /**
     * 查询原材料进场台账列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<BsJctzVo> list(BsJctzBo bo, PageQuery pageQuery) {
        return iBsJctzService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出原材料进场台账列表
     */
    @SaCheckLogin
    @Log(title = "原材料进场台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BsJctzBo bo, HttpServletResponse response) {
        List<BsJctzVo> list = iBsJctzService.queryList(bo);
        ExcelUtil.exportExcel(list, "原材料进场台账", BsJctzVo.class, response);
    }

    /**
     * 获取原材料进场台账详细信息
     *
     * @param tzId 主键
     */
    @SaCheckLogin
    @GetMapping("/{tzId}")
    public R<BsJctzVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long tzId) {
        return R.ok(iBsJctzService.queryById(tzId));
    }

    /**
     * 新增原材料进场台账
     */
    @SaCheckLogin
    @Log(title = "原材料进场台账", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BsJctzBo bo) {
        return toAjax(iBsJctzService.insertByBo(bo));
    }

    /**
     * 修改原材料进场台账
     */
    @SaCheckLogin
    @Log(title = "原材料进场台账", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BsJctzBo bo) {
        return toAjax(iBsJctzService.updateByBo(bo));
    }

    /**
     * 删除原材料进场台账
     *
     * @param tzIds 主键串
     */
    @SaCheckLogin
    @Log(title = "原材料进场台账", businessType = BusinessType.DELETE)
    @DeleteMapping("/{tzIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] tzIds) {
        return toAjax(iBsJctzService.deleteWithValidByIds(Arrays.asList(tzIds), true));
    }
}
